package com.eduhzy.ttw.teacher.di.module;

import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.blankj.utilcode.util.SPUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.core.Constants;
import com.eduhzy.ttw.commonsdk.entity.ClassTeacherData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.teacher.R;
import com.eduhzy.ttw.teacher.mvp.contract.ClassTeacherContract;
import com.eduhzy.ttw.teacher.mvp.model.ClassTeacherModel;
import com.jess.arms.di.scope.ActivityScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;


/**
 * @author xubo
 */
@Module
public abstract class ClassTeacherModule {

    @Binds
    abstract ClassTeacherContract.Model bindClassTeacherModel(ClassTeacherModel model);

    @ActivityScope
    @Provides
    static List<ClassTeacherData> provideList() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    static BaseQuickAdapter<ClassTeacherData, AutoBaseViewHolder> provideActivityAdapter(List<ClassTeacherData> list) {
        return new BaseQuickAdapter<ClassTeacherData, AutoBaseViewHolder>(R.layout.rv_item_class_teacher, list) {
            @Override
            protected void convert(AutoBaseViewHolder helper, ClassTeacherData item) {
                helper.itemView.setBackgroundColor(Color.WHITE);
                Glide.with(helper.itemView.getContext())
                        .load(item.getTempAvatar())
                        .apply(RequestOptions.placeholderOf(R.drawable.img_touxiang).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_avatar));
                helper.setText(R.id.tv_teacher_name, item.getRealName());
                helper.setText(R.id.tv_subject, item.getSubjectName());
                helper.setGone(R.id.iv_right_icon, item.isBzr() && !item.isDelete() && item.getUserId().equals(SPUtils.getInstance().getString(Constants.USERID)));
                helper.setGone(R.id.iv_delete, item.isDelete() && !item.isBzr());
                helper.setGone(R.id.tv_creator, item.isBzr());
                helper.getView(R.id.iv_delete).setSelected(item.isSelect());
                helper.addOnClickListener(R.id.iv_delete);
            }
        };
    }

    @ActivityScope
    @Provides
    static RecyclerView.LayoutManager provideLayoutManger(ClassTeacherContract.View view) {
        return new LinearLayoutManager(view.getActivity());
    }

}